<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Migration_add_table_ci_category extends CI_Migration {

  public function up()
  {
    // Drop table 'ci_option' if it exists   
    $this->dbforge->drop_table('ci_options');

    // Table structure for table 'ci_option'
    $this->dbforge->add_field(array(
      'opt_id' => array(
        'type' => 'INT',
        'constraint' => '11',
        'unsigned' => TRUE,
        'auto_increment' => TRUE
      ),
      'opt_key' => array(
        'type' => 'VARCHAR',
        'constraint' => '255'
      ),
      'opt_value' => array(
        'type' => 'LONGTEXT'
      ),
      'opt_autoload' => array(
        'type' => 'TINYINT',
        'constraint' => '1'
      )
    ));
    $this->dbforge->add_key('opt_id', TRUE);
    $this->dbforge->create_table('ci_options');

    // Drop table 'ci_login_attempts' if it exists   
    $this->dbforge->drop_table('ci_login_attempts');

    // Table structure for table 'ci_login_attempts'
    $this->dbforge->add_field(array(
      'log_id' => array(
        'type' => 'MEDIUMINT',
        'constraint' => '8',
        'unsigned' => TRUE,
        'auto_increment' => TRUE
      ),
      'log_ip_address' => array(
        'type' => 'VARBINARY',
        'constraint' => '16'
      ),
      'log_login' => array(
        'type' => 'VARCHAR',
        'constraint' => '100'
      ),
      'log_time' => array(
        'type' => 'INT',
        'constraint' => '11'
      )
    ));
    $this->dbforge->add_key('log_id', TRUE);
    $this->dbforge->create_table('ci_login_attempts');


    // Drop table 'ci_category_post' if it exists   
    $this->dbforge->drop_table('ci_category_post');

    // Table structure for table 'ci_category_post'
    $this->dbforge->add_field(array(
      'ctp_pos_id' => array(
        'type' => 'INT',
        'constraint' => '11',
        'unsigned' => TRUE
      ),
      'ctp_cat_id' => array(
        'type' => 'INT',
        'constraint' => '11'
      )
    ));
    $this->dbforge->add_key('ctp_pos_id', TRUE);
    $this->dbforge->create_table('ci_category_post');


    // Drop table 'ci_category' if it exists   
    $this->dbforge->drop_table('ci_category');

    // Table structure for table 'ci_category'
    $this->dbforge->add_field(array(
      'cat_id' => array(
        'type' => 'INT',
        'constraint' => '11',
        'unsigned' => TRUE,
        'auto_increment' => TRUE
      ),
      'cat_sort' => array(
        'type' => 'INT',
        'constraint' => '11'
      ),
      'cat_tag_id' => array(
        'type' => 'INT',
        'constraint' => '11'
      ),
      'cat_parent_id' => array(
        'type' => 'INT',
        'constraint' => '11'
      )
    ));
    $this->dbforge->add_key('cat_id', TRUE);
    $this->dbforge->create_table('ci_category');


    // Drop table 'ci_tag' if it exists   
    $this->dbforge->drop_table('ci_tag');

    // Table structure for table 'ci_tag'
    $this->dbforge->add_field(array(
      'tag_id' => array(
        'type' => 'INT',
        'constraint' => '11',
        'unsigned' => TRUE,
        'auto_increment' => TRUE
      ),
      'tag_name' => array(
        'type' => 'VARCHAR',
        'constraint' => '45'
      ),
      'tag_url' => array(
        'type' => 'VARCHAR',
        'constraint' => '45'
      ),
      'tag_cr_uid' => array(
        'type' => 'INT',
        'constraint' => '11'
      ),
      'tag_cr_date' => array(
        'type' => 'DATETIME',
      ),
      'tag_lu_uid' => array(
        'type' => 'INT',
        'constraint' => '11'
      ),
      'tag_lu_date' => array(
        'type' => 'DATETIME',
      )
    ));
    $this->dbforge->add_key('tag_id', TRUE);
    $this->dbforge->create_table('ci_tag');

  }
  public function down()
  {
    $this->dbforge->drop_table('ci_options');
    $this->dbforge->drop_table('ci_login_attempts');
    $this->dbforge->drop_table('ci_category_post');
    $this->dbforge->drop_table('ci_category');
    $this->dbforge->drop_table('ci_tag');
  }

}